<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./cookies.js"></script>
  </head>

  <body>
    <form action="http://www.baidu.com" id="formLogin">
      用户名：<input type="text" name="username" id="ipUsername" /><br />
      密码<input type="password" name="password" id="ipPassword"/><br />
      <button>登录</button>
    </form>

    <script>
      formLogin.onsubmit = function(e){
        // 禁止表单的提交事件跳转action页的默认行为
        e.preventDefault()

        // 将用户名写入cookie
        setCookie("username", ipUsername.value, 3600*1000)

        // 将已登录这一信息写入cookie: logined=true
        setCookie("logined", "true", 3600*1000)

        // 跳转首页
        location.href = "./home.html"
      }
    </script>
  </body>
</html>
